package com.htgd.gardenexpo.controller;


import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.htgd.gardenexpo.entity.CommonResult;
import com.htgd.gardenexpo.entity.GeConThemeActivity;
import com.htgd.gardenexpo.entity.GeMyAddress;
import com.htgd.gardenexpo.page.ThemeActivityQuery;
import com.htgd.gardenexpo.service.IGeConTheaterTimeService;
import com.htgd.gardenexpo.service.IGeConThemeActivityService;
import com.htgd.gardenexpo.utils.TokenUtil;
import com.htgd.gardenexpo.vo.GeConThemeActivityVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 主题活动 前端控制器
 * </p>
 *
 * @author author
 * @since 2025-01-06
 */
@RestController
@RequestMapping("/api/themeActivity")
@Api(tags = "主题活动")
@Slf4j
public class GeConThemeActivityController {

    @Autowired
    private IGeConThemeActivityService geConThemeActivityService;

    @PostMapping(value = "/add")
    @ApiOperation("添加")
    public CommonResult add (@RequestBody GeConThemeActivity geConThemeActivity, HttpServletRequest request) {
        String accessToken = request.getHeader("Access_token");
        String username = TokenUtil.getUsernameFromToken(accessToken);
        log.info("主题活动-添加:{},{}", geConThemeActivity,username);
        return geConThemeActivityService.add(geConThemeActivity,username);
    }

    @PostMapping(value = "/edit")
    @ApiOperation("编辑")
    public CommonResult edit (@RequestBody GeConThemeActivity geConThemeActivity) {
        log.info("主题活动-编辑:{}", geConThemeActivity);
        return geConThemeActivityService.edit(geConThemeActivity);
    }

    @DeleteMapping(value = "/delete")
    @ApiOperation("删除")
    public CommonResult delete (String id) {
        log.info("主题活动-删除:{}", id);
        return geConThemeActivityService.delete(id);
    }

    @GetMapping(value = "/list")
    @ApiOperation("查询")
    public CommonResult<List<GeConThemeActivityVO>> list (ThemeActivityQuery themeActivityQuery) {
        log.info("主题活动-查询:{}", themeActivityQuery);
        PageInfo<GeConThemeActivityVO> list = geConThemeActivityService.pageList(themeActivityQuery);
        return CommonResult.success(String.valueOf(list.getTotal()),list.getList());
    }

    @GetMapping(value = "/details")
    @ApiOperation("详情")
    public CommonResult<GeConThemeActivityVO> details (String id) {
        log.info("主题活动-详情:{}", id);
        return geConThemeActivityService.details(id);
    }


    @PostMapping(value = "/review")
    @ApiOperation("审批")
    public CommonResult review (@RequestBody GeConThemeActivity geConThemeActivity) {
        log.info("主题活动-审批:{}", geConThemeActivity);
        return geConThemeActivityService.review(geConThemeActivity);
    }


}
